
class ScorePanel {
    // score和level用来记录分数和等级
    score = 0;
    level = 1;

    // 分数和等级所在的元素
    scoreEle: HTMLElement;
    levelEle: HTMLElement;

    // 每 n 分 升一级
    upScore: number;
    // 最大难度等级
    maxLevel: number;
    constructor(maxLevel: number = 10, upScore: number = 10) {
        this.scoreEle = document.getElementById('score')!;
        this.levelEle = document.getElementById('level')!;
        this.maxLevel = maxLevel;
        this.upScore = upScore;
    }
    addScore() {
        this.scoreEle.innerHTML = ++this.score + '';
        if (this.score % this.upScore === 0) {
            this.levelUp();
        }
    }
    levelUp() {
        if (this.level < this.maxLevel) {
            this.levelEle.innerHTML = ++this.level + '';
        }
    }
}

export default ScorePanel;

// 测试 计分板
// const scorePanel = new ScorePanel(100, 2);
// for (let i = 0; i < 200; i++) {
//     scorePanel.addScore();
// }